<?php
namespace app\home\controller;
use think\Db;
use think\Controller;
use think\Request;
class Login extends Controller
{
    public function Index()
    {
        return view('home@home/Login');
    }


    /**
     * 前台登录处理
     * @return \think\response\View
     */
    public function DoLogin()
    {
        $data = $_POST;
//        var_dump($data);die;
        $email = $data['email'];
//        var_dump($data);die;
        $res = Db::table('user')->where('email', $email)->find();
//        var_dump($res);die;
        if (!$email) {
            $this->error('用户邮箱不存在！', 'home/Login/Index');
        }
        if (!$data['pwd']) {
            $this->error('密码不存在！', 'home/Login/Index');
        }

        session('user', $res);
//        dump($a);die;
        if ($data['pwd']==$res['pwd']&&$email==$res['email']){
            $this->success('登录成功！','home/Index/Index');
        }else{
            $this->error('登录失败！','home/Index/Index');

        }
    }

}
